package com.lc.cehui.ui.activity.land;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.cehui.R;
import com.lc.cehui.app.AppActivity;
import com.lc.cehui.http.request.ForgetNewpwdApi;
import com.lc.cehui.http.request.ForgetPwdApi;
import com.lc.cehui.http.response.CodeBean;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SetNewPasswordActivity extends AppActivity {

    @BindView(R.id.et_mm)
    EditText etMm;
    @BindView(R.id.et_qrmm)
    EditText etQrmm;
    @BindView(R.id.bt_submit)
    Button btSubmit;
    @BindView(R.id.bt_cancel)
    Button btCancel;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_set_new_password;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.bt_submit, R.id.bt_cancel})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_submit:
                forget();
                startActivity(LoginActivity.class);
                break;
            case R.id.bt_cancel:
                finish();
                break;
        }
    }

    private void forget() {
        EasyHttp.post(this)
                .api(new ForgetPwdApi()
                        .setMobile(getIntent().getStringExtra("mobile")).setPassword(etMm.getText().toString()).setRepassword(etQrmm.getText().toString()))
                .request(new HttpCallback<CodeBean>(this) {

                    @Override
                    public void onSucceed(CodeBean data) {
                        toast(data.getMsg());
                        if (data.getCode().equals("200")){
                            finish();
                        }
                    }
                });

    }
}